/**
 * 
 */
package com.wubo.bm.user.service.impl;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.wubo.bm.user.entity.UserInfo;
import com.wubo.bm.user.service.IUserInfoService;
import com.wubo.sec.model.User;
import com.wubo.sec.service.IUserService;
import com.wubo.spring.hibernate.BaseHibernateDao;
import com.wubo.spring.hibernate.EntityService;

/**
 * @author WuBo
 * @CreateDate 2012-3-28 下午02:46:51
 */
@Service
public class UserInfoService extends EntityService<UserInfo> implements IUserInfoService {
	@Resource
	private IUserService userService;
	
	@Autowired
	public UserInfoService(BaseHibernateDao dao){
		super.setDao(dao);
	}
	
	@Override
	public void saveOrUpdateBasicInfo(UserInfo userInfo, User user) {
		User temp = getDao().get(User.class, user.getUsername());
		temp.setEmail(user.getEmail());
		temp.setTruename(user.getTruename());
		temp.setNickname(user.getNickname());
		
		userService.updateSelf(temp);
		if(userInfo.getId() != null && userInfo.getId() > 0){
			UserInfo ui = super.get(userInfo.getId());
			ui.setAge(userInfo.getAge());
			ui.setGender(userInfo.getGender());
			ui.setBloodType(userInfo.getBloodType());
			super.update(ui);
		}else{
			super.save(userInfo);
		}
	}
	
	public void saveOrUpdateMoreInfo(UserInfo userInfo, User user){
		if(userInfo.getId() != null && userInfo.getId() > 0){
			UserInfo ui = super.get(userInfo.getId());
			ui.setBirthday(userInfo.getBirthday());
			ui.setBirthdayType(userInfo.getBirthdayType());
			ui.setCellphone(userInfo.getCellphone());
			ui.setCity(userInfo.getCity());
			ui.setCountry(userInfo.getCountry());
			ui.setCounty(userInfo.getCounty());
			ui.setDepartment(userInfo.getDepartment());
			ui.setJob(userInfo.getJob());
			ui.setOrg(userInfo.getOrg());
			ui.setProvince(userInfo.getProvince());
			ui.setTelephone(userInfo.getTelephone());
			ui.setAddress(userInfo.getAddress());
			super.update(ui);
		}else{
			super.save(userInfo);
		}
	}
}
